﻿using internetmanage.jiemian;
using System;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;
using WindowsApplication1.jiemian;

namespace WindowsApplication1
{
    public partial class Form_main : Form
    {
        public Form_main()
        {
            InitializeComponent();
        }

        /// <summary>
        /// tian jia ti mu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// tian jia lei bie
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton4_Click(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// dao ru
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            try
            {
                //string strFileName = (DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ".log").Replace(":", "");
                StreamWriter sw4 = new StreamWriter("classes\\" + "1.log", false, Encoding.Default);
                sw4.WriteLine("");
                sw4.Flush();
                sw4.Close();
                int chongfu = 0;
                int daoru = 0;

                //da kai wen jian
                string str_file = "";
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                openFileDialog1.Filter = "xsl数据文件(*.csv)|*.*";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    str_file = openFileDialog1.FileName;
                }

                if (string.IsNullOrEmpty(str_file)) { return; }
                //读取所有csv文件 手机号记入数组
                ArrayList al = new ArrayList();
                DirectoryInfo di = new DirectoryInfo("classes");
                FileInfo[] f1 = di.GetFiles("*.csv", SearchOption.AllDirectories);
                foreach (FileInfo f2 in f1)
                {
                    StreamReader sr = f2.OpenText();
                    sr.ReadLine();
                    string xinxi = sr.ReadLine();
                    if (string.IsNullOrEmpty(xinxi)) { continue; }
                    string[] xin = xinxi.Split(',');
                    string x = xin[4];
                    al.Add(x);
                    sr.Close();
                }

                //读取导入文件
                StreamReader sr1 = new StreamReader(str_file, Encoding.Default);
                string title = sr1.ReadLine();
                while (!sr1.EndOfStream)
                {
                    string xinxi = sr1.ReadLine();
                    string[] xin = xinxi.Split(',');
                    string x = xin[4];

                    if (al.Contains(x))
                    {
                        //MessageBox.Show(xin[4] + "手机号重复");
                        StreamWriter sw1 = new StreamWriter("classes\\" + "1.log", true, Encoding.Default);
                        sw1.WriteLine(xin[0] + " " + xin[4] + "手机号重复");
                        chongfu++;
                        sw1.Flush();
                        sw1.Close();
                    }
                    else
                    {
                        StreamWriter sw = new StreamWriter("classes\\" + xin[0] + ".csv", false, Encoding.Default);
                        sw.WriteLine(title);
                        sw.WriteLine(xinxi);
                        daoru++;
                        sw.Flush();
                        sw.Close();

                        StreamWriter sw1 = new StreamWriter("classes\\" + "1.log", true, Encoding.Default);
                        sw1.WriteLine(xin[0] + " " + xin[4] + "导入");
                        sw1.Flush();
                        sw1.Close();
                    }
                }

                sr1.Close();

                StreamWriter sw2 = new StreamWriter("classes\\" + "1.log", true, Encoding.Default);
                sw2.WriteLine("");
                sw2.WriteLine("导入：" + daoru.ToString());
                sw2.WriteLine("重复：" + chongfu.ToString());
                sw2.Flush();
                sw2.Close();

                //hou xu
                load_fenlei();
                Process.Start("classes\\1.log");

                //StreamReader s2 = new StreamReader("classes\\1.log", Encoding.Default);

                //if (string.IsNullOrEmpty(s2.ReadToEnd()))
                //{
                //    MessageBox.Show("导入完成");
                //}
                //else
                //{
                //    Process.Start("classes\\1.log");
                //}
                //s2.Close();
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.ToString());
            }
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// liu lan ti mu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            load_fenlei();
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (treeViewDirect.SelectedNode.Tag == "r")
            {
                load_fenlei();
            }
            else if (treeViewDirect.SelectedNode.Tag == "d")
            {
                LoadDir();
            }
            else if (treeViewDirect.SelectedNode.Tag == "f")
            {
                LoadText();
            }
        }

        private void LoadText()
        {
            try
            {
                string path = treeViewDirect.SelectedNode.FullPath;
                StreamReader sr = new StreamReader(path, Encoding.Default);
                string temp = sr.ReadToEnd();
                sr.Close();
                this.richTextBox1.Text = "";
                this.richTextBox1.Text = temp;
                this.richTextBox1.Tag = path;
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.ToString());
            }
        }

        private void LoadDirectory(TreeNode tn)
        {
            tn.Nodes.Clear();
            string path = tn.FullPath;


            string[] dirs = Directory.GetDirectories(path);
            foreach (string s in dirs)
            {
                TreeNode treeNodeNew = new TreeNode(Path.GetFileName(s));
                treeNodeNew.Tag = "d";
                treeNodeNew.ImageKey = "dirClose.bmp";
                treeNodeNew.SelectedImageKey = "dirOpen.bmp";
                tn.Nodes.Add(treeNodeNew);
                //treeView1.Nodes[0].Nodes.Add(tnNew);

                //LoadDirectory(tnNew);
                //treeView1.SelectedNode = tnNew;
            }



            string[] files = Directory.GetFiles(path);
            foreach (string s in files)
            {
                TreeNode tnNew = new TreeNode(Path.GetFileName(s));
                tnNew.Tag = "f";
                tnNew.ImageKey = "txt.bmp";
                tnNew.SelectedImageKey = "zz_txt.bmp";
                tn.Nodes.Add(tnNew);
                //treeView1.SelectedNode = tnNew;
            }




            tn.ExpandAll();
        }

        private void LoadDir()
        {
            LoadDirectory(treeViewDirect.SelectedNode);
            //treeView1.SelectedNode.Nodes.Clear();
            //string path = treeView1.SelectedNode.FullPath;
            //string[] dirs = Directory.GetFiles(path);
            //foreach (string s in dirs)
            //{
            //    TreeNode tnNew = new TreeNode(Path.GetFileName(s));
            //    tnNew.Tag = "f";
            //    tnNew.ImageKey = "txt.bmp";
            //    tnNew.SelectedImageKey = "txt.bmp";
            //    treeView1.SelectedNode.Nodes.Add(tnNew);
            //    //treeView1.SelectedNode = tnNew;
            //}

            //treeView1.SelectedNode.ExpandAll();
        }

        /// <summary>
        /// tian jia xiu gai ti mu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton2_Click_1(object sender, EventArgs e)
        {
        }

        private void RefreshColor(TreeNode tn)
        {
            tn.ForeColor = SystemColors.ControlText;
            foreach (TreeNode tnOne in tn.Nodes)
            {
                RefreshColor(tnOne);
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (this.toolStripTextBox1.Text.Trim() == "")
            { return; }
            //if (treeView1.SelectedNode == null) { return; }
            foreach (TreeNode tn in treeViewDirect.Nodes)
            {
                RefreshColor(tn);
            }
            //treeView1.SelectedNode.ForeColor = Color.Blue;
            treeViewDirect.Nodes[0].ForeColor = Color.Blue;
            FindFile(treeViewDirect.Nodes[0], this.toolStripTextBox1.Text.Trim());
        }

        private void FindFile(TreeNode treeNode, string strSearch)
        {
            foreach (TreeNode subNode in treeNode.Nodes)
            {
                if (subNode.Text.ToUpper().IndexOf(strSearch.ToUpper()) != -1)
                {
                    subNode.ForeColor = Color.Red;
                    subNode.Parent.Expand();
                }
                FindFile(subNode, strSearch);
            }

            //treeNode.Nodes.Clear();
            //DirectoryInfo diRoot = new DirectoryInfo(treeNode.FullPath);
            //FileInfo[] theFiles = diRoot.GetFiles();
            //foreach (FileInfo theFile in theFiles)
            //{
            //    TreeNode subNode = new TreeNode(theFile.Name);
            //    subNode.Tag = "f";
            //    subNode.ImageKey = "txt.bmp";
            //    subNode.SelectedImageKey = "txt.bmp";
            //    if (subNode.Text.ToUpper().IndexOf(strSearch.ToUpper()) != -1)
            //    {
            //        subNode.ForeColor = Color.Red;

            //    }

            //    treeNode.Nodes.Add(subNode);

            //    if (subNode.Text.ToUpper().IndexOf(strSearch.ToUpper()) != -1)
            //    {
            //        subNode.ForeColor = Color.Red;
            //        subNode.Parent.Expand();
            //    }

            //}
        }

        private void load_fenlei()
        {
            treeViewDirect.Nodes[0].Nodes.Clear();
            string path = "classes";
            string[] dirs = Directory.GetDirectories(Path.Combine(Application.StartupPath, path));

            //string[] dirs = Directory.GetDirectories(path);
            foreach (string s in dirs)
            {
                TreeNode tnNew = new TreeNode(Path.GetFileName(s));
                tnNew.Tag = "d";
                tnNew.ImageKey = "dirClose.bmp";
                tnNew.SelectedImageKey = "dirOpen.bmp";
                treeViewDirect.Nodes[0].Nodes.Add(tnNew);

                LoadDirectory(tnNew);
                //treeView1.SelectedNode = tnNew;
            }

            string[] files = Directory.GetFiles(path);
            foreach (string s in files)
            {
                TreeNode tnNew = new TreeNode(Path.GetFileName(s));
                tnNew.Tag = "f";
                tnNew.ImageKey = "txt.bmp";
                tnNew.SelectedImageKey = "zz_txt.bmp";
                treeViewDirect.Nodes[0].Nodes.Add(tnNew);
                //treeView1.SelectedNode = tnNew;
            }

            treeViewDirect.Nodes[0].ExpandAll();
        }

        //private void load_feilei_file() {
        //    load_fenlei();

        //}

        private void Form_main_Load(object sender, EventArgs e)
        {
            treeViewDirect.Nodes.Clear();
            TreeNode treeNode = new TreeNode();
            treeNode.Text = "classes";
            treeNode.Tag = "d";
            treeNode.ImageKey = "dir.bmp";
            treeNode.SelectedImageKey = "dir.bmp";
            treeViewDirect.Nodes.Add(treeNode);

            load_fenlei();

            Form_send.tmpCookies = new CookieCollection();
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 建立分类ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            createDirectory();
        }

        private void createDirectory()
        {
            //string root = Application.StartupPath + "\\分类";

            //string strFileName = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(":", "");
            //Directory.CreateDirectory(Path.Combine(root, strFileName));

            //TreeNode tnNew = new TreeNode(strFileName);
            //tnNew.Tag = "d";
            //treeView1.Nodes[0].Nodes.Add(tnNew);
            //treeView1.SelectedNode = tnNew;

            try
            {
                if (this.treeViewDirect.SelectedNode.Tag.ToString() == "d")
                {
                    string strFileName = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(":", "");
                    string strFile = Path.Combine(this.treeViewDirect.SelectedNode.FullPath.ToString(), strFileName);
                    Directory.CreateDirectory(strFile);
                    TreeNode tnNew = new TreeNode(strFileName);


                    tnNew.Tag = "d";
                    tnNew.ImageKey = "dirClose.bmp";
                    tnNew.SelectedImageKey = "dirOpen.bmp";
                    //ArrayList arrayListTag = new ArrayList();
                    //arrayListTag.Add(strFile);
                    //arrayListTag.Add("d");
                    //tnNew.Tag = arrayListTag;

                    //TreeViewHelper.ChangeFileIco(tnNew);

                    treeViewDirect.SelectedNode.Nodes.Add(tnNew);
                    treeViewDirect.SelectedNode = tnNew;
                }
                else
                {
                    string strFile = Path.Combine(this.treeViewDirect.SelectedNode.Parent.FullPath.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Replace(":", "");
                    Directory.CreateDirectory(strFile);
                    TreeNode tnNew = new TreeNode(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(":", ""));

                    //ArrayList arrayListTag = new ArrayList();
                    //arrayListTag.Add(strFile);
                    //arrayListTag.Add("d");
                    //tnNew.Tag = arrayListTag;
                    tnNew.Tag = "d";
                    tnNew.ImageKey = "dirClose.bmp";
                    tnNew.SelectedImageKey = "dirOpen.bmp";
                    //TreeViewHelper.ChangeFileIco(tnNew);

                    treeViewDirect.SelectedNode.Parent.Nodes.Add(tnNew);
                    treeViewDirect.SelectedNode = tnNew;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItemCreateFile_Click(object sender, EventArgs e)
        {
            createFile();
        }

        private void createFile()
        {
            if (this.treeViewDirect.SelectedNode.Tag == "d")
            {
                string path = treeViewDirect.SelectedNode.FullPath;
                string strFileName = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(":", "");
                //File.Create(Path.Combine(path, strFileName + ".txt"));

                string temp = "url:\n\npost:\n\n\n\nmethod:\npost\n";
                StreamWriter sw = new StreamWriter(Path.Combine(path, strFileName + ".txt"), false, Encoding.Default);
                sw.Write(temp);
                sw.Flush();
                sw.Close();

                TreeNode tnNew = new TreeNode(strFileName + ".txt");
                tnNew.Tag = "f";
                tnNew.ImageKey = "txt.bmp";
                tnNew.SelectedImageKey = "zz_txt.bmp";
                treeViewDirect.SelectedNode.Nodes.Add(tnNew);
                treeViewDirect.SelectedNode = tnNew;
            }
            else
            {
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control == true)
            {
                if (e.KeyValue == 83)
                {
                    Encoding encode = Encoding.Default;
                    string temp = this.richTextBox1.Text;
                    StreamWriter sw = new StreamWriter(richTextBox1.Tag.ToString(), false, encode);
                    sw.Write(temp);
                    sw.Flush();
                    sw.Close();
                }
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyData == Keys.F2)
                {
                    StartRename();
                }
                else if (e.KeyData == Keys.Delete)
                {
                    this.richTextBox1.Text = "";
                    FileCtrl.PutRececal(treeViewDirect.SelectedNode.FullPath.ToString());
                    treeViewDirect.SelectedNode.Remove();
                }

                else if (e.KeyData == Keys.F3)
                {
                    //ToolStripMenuItem_Click_add("txt");
                    createFile();

                }
                else if (e.KeyData == Keys.F4)
                {
                    createDirectory();
                }
                else if (e.KeyData == Keys.F5)
                {
                    openDefault();
                }
                //else if (e.KeyData == Keys.F6)
                //{
                //    accessWeb();

                //    //if (((ArrayList)treeViewDirect.SelectedNode.Tag)[1].ToString() == "d")
                //    //{
                //    //    fangwen_file();
                //    //}
                //    //else
                //    //{
                //    //    fangwen(Path.GetExtension(treeViewDirect.SelectedNode.Text));
                //    //}
                //}
                else if (e.KeyData == Keys.F6)
                {
                    Form_xml fs = new Form_xml();

                    fs.stringxml = this.richTextBox1.Text;

                    fs.Show();

                    fs.readXml();
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.ToString());
            }
        }

        /// <summary>
        /// Places the currently selected node in rename mode.
        /// </summary>
        public void StartRename()
        {
            try
            {
                if (this.treeViewDirect.SelectedNode != null)
                {
                    treeViewDirect.LabelEdit = true;
                    treeViewDirect.SelectedNode.BeginEdit();
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            try
            {
                if (e.Node.Text == e.Label || e.Label == null) { return; }

                if ((!e.CancelEdit) && (string.Compare(e.Label, e.Node.Text, false) != 0))
                {
                    if (e.Node.Tag.ToString() == "d")
                    {
                        DirectoryInfo d = new DirectoryInfo(e.Node.FullPath.ToString());
                        string strDir = d.FullName.Substring(0, d.FullName.LastIndexOf("\\") + 1) + e.Label;
                        d.MoveTo(strDir);

                        this.treeViewDirect.SelectedNode = e.Node;
                        treeViewDirect.LabelEdit = false;

                        //LoadDirAndFile(e.Node);
                        return;
                    }

                    if (e.Node.Tag.ToString() == "f")
                    {
                        string strFile = Path.Combine(Path.GetDirectoryName(e.Node.FullPath), e.Label);
                        this.MoveFile(e.Node.FullPath, strFile);
                        treeViewDirect.LabelEdit = false;
                        e.Node.Text = e.Label;
                        this.treeViewDirect.SelectedNode = e.Node;
                        LoadText();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        public void MoveFile(string oldUrlName, string newUrlName)
        {
            if (System.IO.File.Exists(oldUrlName))
            {
                System.IO.File.Move(oldUrlName, newUrlName);

                System.IO.File.Delete(oldUrlName);
            }
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            openDefault();
            //if (this.treeView1.SelectedNode.Tag == "f")
            //{
            //}
            //else {
            //}
        }

        private void openDefault()
        {
            Process.Start(treeViewDirect.SelectedNode.FullPath);
        }

        private void treeView1_DragDrop(object sender, DragEventArgs e)
        {
            Point targetPoint = treeViewDirect.PointToClient(new Point(e.X, e.Y));
            TreeNode targetNode = treeViewDirect.GetNodeAt(targetPoint);
            TreeNode draggedNode = (TreeNode)e.Data.GetData(typeof(TreeNode));

            string newPath;
            string oldPath;

            if (draggedNode.Tag != "f") { return; }

            if (!draggedNode.Equals(targetNode))
            {
                if (e.Effect == DragDropEffects.Move)
                {
                    if (targetNode.Tag == "f")
                    {
                        oldPath = draggedNode.FullPath.ToString();
                        newPath = Path.Combine(targetNode.Parent.FullPath.ToString(), draggedNode.Text);

                        File.Move(oldPath, newPath);
                        draggedNode.Remove();
                        draggedNode.Tag = "f";

                        targetNode.Parent.Nodes.Add(draggedNode);
                        targetNode.Parent.Expand();
                    }
                    else
                    {
                        oldPath = draggedNode.FullPath.ToString();
                        newPath = Path.Combine(targetNode.FullPath.ToString(), draggedNode.Text);

                        File.Move(oldPath, newPath);
                        draggedNode.Remove();
                        draggedNode.Tag = "f";

                        targetNode.Nodes.Add(draggedNode);
                        targetNode.Parent.Expand();
                    }
                }
            }
        }

        private void treeView1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = e.AllowedEffect;
        }

        private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
        {
            try
            {
                if (e.Button == MouseButtons.Left)
                {
                    DoDragDrop(e.Item, DragDropEffects.Move);
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }

        /// <summary>
        /// dao chu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton2_Click_2(object sender, EventArgs e)
        {
            try
            {
                string strFileName = ("备份\\" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ".csv").Replace(":", "");

                //FileStream fs = File.Create(strFile);

                string temp = "姓名,昵称,性别,QQ/TM帐号,常用手机,备用手机,小灵通,工作电话,家庭电话,其它电话,常用邮箱,备用邮箱,单位地址-邮编,单位地址-国家/地区,单位地址-省,单位地址-市,单位地址-街道,住宅地址-邮编,住宅地址-国家/地区,住宅地址-省,住宅地址-市,住宅地址-街道,其它地址-邮编,其它地址-国家/地区,其它地址-省,其它地址-市,其它地址-街道,公司名称,隶属行业,部门名称,职务名称,生日,简介与备注";
                StreamWriter sw = new StreamWriter(strFileName, false, Encoding.Default);
                sw.Write(temp);

                string path = "classes";
                string[] dirs = Directory.GetDirectories(Path.Combine(Application.StartupPath, path));
                foreach (string s in dirs)
                {
                    if (s.IndexOf("废") == -1)
                    {
                        string[] files1 = Directory.GetFiles(s);
                        foreach (string s1 in files1)
                        {
                            //StreamReader sr = new StreamReader(s1);
                            StreamReader sr = new StreamReader(s1, Encoding.Default);
                            sr.ReadLine();
                            string content = sr.ReadLine();
                            sw.WriteLine(content);
                        }
                    }
                }

                string[] files = Directory.GetFiles(path);
                foreach (string s in files)
                {
                    StreamReader sr = new StreamReader(s, Encoding.Default);
                    sr.ReadLine();
                    string content = sr.ReadLine();
                    sw.WriteLine(content);
                }

                sw.Flush();
                sw.Close();
                //MessageBox.Show("导出成功");
                Process.Start("备份");
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.ToString());
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 访问ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            accessWeb();
        }

        private void accessWeb()
        {
            TreeNode tn = this.treeViewDirect.SelectedNode;
            string file_path = tn.FullPath;
            StreamReader sr = new StreamReader(file_path);
            bool isurl = false;
            bool ispost = false;
            bool ismethod = false;
            bool isimg = false;
            bool isencoding = false;

            string url = "";
            string post = "";
            string method = "";
            string encoding = "";

            while (!sr.EndOfStream)
            {
                string temp = sr.ReadLine();
                if (!string.IsNullOrEmpty(temp.Trim()))
                {
                    if (temp.IndexOf("url:") != -1)
                    {
                        isurl = true;
                    }
                    else if (temp.IndexOf("post:") != -1)
                    {
                        ispost = true;
                        isurl = false;
                    }
                    else if (temp.IndexOf("method:") != -1)
                    {
                        ismethod = true;
                        ispost = false;
                        isurl = false;
                    }
                    else if (temp.IndexOf("img:") != -1)
                    {
                        isimg = true;
                    }
                    else if (temp.IndexOf("encoding:") != -1)
                    {
                        isencoding = true;
                    }
                    else if (isencoding)
                    {
                        encoding = temp.Trim();
                        isencoding = false;
                    }
                    else if (isurl)
                    {
                        url = temp.Trim();
                        isurl = false;
                    }
                    else if (ispost)
                    {
                        post += temp.Trim();
                    }
                    else if (ismethod)
                    {
                        method = temp.Trim();
                        ismethod = false;
                    }
                }
            }
            sr.Close();

            Form_send fs = new Form_send();

            fs.url = url;
            fs.post = post;
            fs.method = method;
            fs.isimg = isimg;
            fs.encoding = encoding;
            fs.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
        }

        private void toolStripButton2_Click_3(object sender, EventArgs e)
        {
            Form_send.tmpCookies = new CookieCollection();

            string temp = "";
            foreach (Cookie c in Form_send.tmpCookies)
            {
                temp += c.ToString();
            }

            this.richTextBox1.Text = temp;
        }

        /// <summary>
        /// cha kan cookie
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton3_Click_1(object sender, EventArgs e)
        {
            string temp = "";
            foreach (Cookie c in Form_send.tmpCookies)
            {
                temp += c.ToString() + "\n";
            }

            this.richTextBox1.Text = temp;
        }

        private void toolStripButtonencrypt_Click(object sender, EventArgs e)
        {
            Form_encrypt fs = new Form_encrypt();
            fs.Show();
        }

        private void toolStripButton4_Click_1(object sender, EventArgs e)
        {
            Form_json fs = new Form_json();
            fs.Show();
        }

        private void xmlToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_xml fs = new Form_xml();

            fs.stringxml = this.richTextBox1.Text;

            fs.Show();
        }

        private void toolStripButton4_Click_2(object sender, EventArgs e)
        {
            Form_xml fs = new Form_xml();
            fs.Show();
        }
    }
}